package com.animal.controller;

import com.animal.common.Constants;
import com.animal.common.Result;
import com.animal.entity.pojo.ABlog;
import com.animal.entity.pojo.AComment;
import com.animal.entity.pojo.R;
import com.animal.entity.pojo.Reply;
import com.animal.entity.vo.ABlogVo;
import com.animal.service.ABlogService;
import com.animal.service.ReplyService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 回复博客
 */
@RestController
@RequestMapping("/reply")
public class ReplyController {


    /**
     * 回复博客
     */
    @Autowired
    private ReplyService replyService;
    @Autowired
    private ABlogService blogService;


    /**
     *博客&评论列表
     * @return
     */
    @ResponseBody
    @PostMapping("/commentlist/{pageNo}/{pageSize}")
    public Result selectAllComment(
                                   @PathVariable Integer pageNo,
                                   @PathVariable Integer pageSize
    ){
        List<ABlogVo> list = blogService.getBlog();
        PageHelper.startPage(pageNo, pageSize);
        PageInfo<ABlogVo> pageInfo = new PageInfo<>(list);
        return Result.success(Constants.CODE_200,"",pageInfo);
    }

    @PostMapping("/add")
    public R add(@RequestBody Reply reply){
        if (replyService.publish(reply)){
            return R.success("回复成功！");
        }
        return R.error("失败！");
    }

}
